package com.ccsu.mymarket.exception;

import com.ccsu.mymarket.entity.message.Meta;
import com.ccsu.mymarket.entity.message.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExcptionHandler {
    /**
     * 自定义异常
     * @param e
     * @return 返回异常发生时的自定义信息
     */
    @ExceptionHandler(MyException.class)
    public Result MyException(MyException e){
        log.error(e.getMessage(),e);
        return new Result(new Meta(403, e.getMessage()), null);
    }

}
